package com.www.applyword.ui.my;

import android.text.TextUtils;
import android.widget.TextView;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.EducationAdapter;
import com.www.applyword.adapter.SkillAdapter;
import com.www.applyword.adapter.WordHopeAdapter;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.ResumeBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.utils.ImageUtil;
import com.www.applyword.utils.SPUtil;
import com.www.applyword.utils.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * author : huang
 * date   : 2019/10/24 0024 14:44
 * version: 1.0
 * @author Administrator
 */
public class PersonalResumeActivity extends BaseActivity {
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.civ_head_photo)
    CircleImageView civHeadPhoto;
    @BindView(R.id.tv_personal)
    TextView tvPersonal;
    @BindView(R.id.tv_appraise)
    TextView tv_appraise;
    @BindView(R.id.rl_word_hope)
    RecyclerView rlWordHope;
    @BindView(R.id.rl_word_time)
    RecyclerView rlWordTime;
    @BindView(R.id.rl_education)
    RecyclerView rl_education;
    @BindView(R.id.rl_skill)
    RecyclerView rl_skill;
    @BindView(R.id.rl_word_time2)
    RecyclerView rlWordTime2;

    @BindView(R.id.tv_job_type)
    TextView tvJobType;
    @BindView(R.id.tv_job_qiyu)
    TextView tvJobQiyu;
    @BindView(R.id.tv_hope_job)
    TextView tvHopeJob;
    @BindView(R.id.tv_leisure_time)
    TextView tvLeisureTime;
    @BindView(R.id.tv_hope_money)
    TextView tvHopeMoney;
    @BindView(R.id.tv_job_time)
    TextView tvJobTime;

    private WordHopeAdapter wordHopeAdapter;
    private WordHopeAdapter wordHopeAdapter2;
    private EducationAdapter educationAdapter;
    private SkillAdapter skillAdapter;
    private List<ResumeBean.ResumeWorkBean> resumeWork  = new ArrayList<>();
    private List<ResumeBean.ResumeSchoolBean> schoolBeans  = new ArrayList<>();
    private List<ResumeBean.ResumeCertificateBean> certificateBeans  = new ArrayList<>();
    private ResumeBean.ResumeBasicBean resumeBasic;


    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.personal_resume_activity);
        setTitle("个人简历");
        Constants.type = 2;
    }

    @Override
    protected void loadData() {
       String userId = getIntent().getStringExtra("user_id");
        rlWordTime.setLayoutManager(new LinearLayoutManager(PersonalResumeActivity.this));
        rlWordTime.setItemAnimator(new DefaultItemAnimator());
        wordHopeAdapter = new WordHopeAdapter(PersonalResumeActivity.this);
        rlWordTime.setAdapter(wordHopeAdapter);
     //   rlWordTime.setHasFixedSize(true);
        rlWordTime.setNestedScrollingEnabled(false);

        rlWordTime2.setLayoutManager(new LinearLayoutManager(PersonalResumeActivity.this));
        rlWordTime2.setItemAnimator(new DefaultItemAnimator());
        wordHopeAdapter2 = new WordHopeAdapter(PersonalResumeActivity.this);
        rlWordTime2.setAdapter(wordHopeAdapter2);
       // rlWordTime2.setHasFixedSize(true);
        rlWordTime2.setNestedScrollingEnabled(false);

        rl_education.setLayoutManager(new LinearLayoutManager(PersonalResumeActivity.this));
        rl_education.setItemAnimator(new DefaultItemAnimator());
        educationAdapter = new EducationAdapter(PersonalResumeActivity.this);
        rl_education.setAdapter(educationAdapter);
      //  rl_education.setHasFixedSize(true);
        rl_education.setNestedScrollingEnabled(false);

        rl_skill.setLayoutManager(new LinearLayoutManager(PersonalResumeActivity.this));
        rl_skill.setItemAnimator(new DefaultItemAnimator());
        skillAdapter = new SkillAdapter(PersonalResumeActivity.this);
        rl_skill.setAdapter(skillAdapter);
       // rl_skill.setHasFixedSize(true);
        rl_skill.setNestedScrollingEnabled(false);

        Map<String, Object> params = new HashMap<>();
        if (TextUtils.isEmpty(userId)){
            params.put("UserID", SPUtil.getString(Constants.USERID));
        }else {
            params.put("UserID", userId);
        }

        HttpClient.get(PersonalResumeActivity.this, Constants.GETALLRESUME, params, new CallBack<ResumeBean>() {
            @Override
            public void onSuccess(ResumeBean result) {
                resumeBasic = result.getResumeBasic();
                String year1 = Utils.getYear(System.currentTimeMillis());
                String year2 = resumeBasic.getResumeBasic_DateOfBirth().substring(0, 4);
                int year3 = Integer.valueOf(year1) - Integer.valueOf(year2);
                tvName.setText(result.getResumeBasic().getResumeBasic_UserName());
                ImageUtil.setImage(civHeadPhoto, result.getResumeBasic().getResumeBasic_HeadImg());
                tvPersonal.setText(year3 + "岁" + "|" + resumeBasic.getResumeBasic_Sex() + "|" + resumeBasic.getResumeBasic_City() + "|" + resumeBasic.getResumeBasic_HighestDiploma()
                        +  "|" + resumeBasic.getResumeBasic_EducationalStatus() + "|" + "身高:" + resumeBasic.getResumeBasic_Height() + "cm"
                         + "\n" + "手机号:" + resumeBasic.getResumeBasic_Mobile());
                tv_appraise.setText(resumeBasic.getResumeBasic_Evaluate());
                tvJobType.setText(resumeBasic.getResumeBasic_WorkNature()); //我想找长期稳定工作
                tvJobQiyu.setText(resumeBasic.getResumeBasic_Region());
                tvHopeJob.setText(resumeBasic.getResumeBasic_PositionName());
                tvLeisureTime.setText(resumeBasic.getResumeBasic_FreeTime());
                tvHopeMoney.setText(resumeBasic.getResumeBasic_SalaryExpectation());
                tvJobTime.setText(resumeBasic.getResumeBasic_WorkTime());

                resumeWork.clear();
                resumeWork.addAll(result.getResumeWork());
                wordHopeAdapter.replaceAll(resumeWork, true);

              //  resumeWork2.addAll(result.getResumeWork());
                wordHopeAdapter2.replaceAll(result.PlatformResumeWork, true);

                schoolBeans.clear();
                schoolBeans.addAll(result.getResumeSchool());
                educationAdapter.replaceAll(schoolBeans, true);

                certificateBeans.clear();
                certificateBeans.addAll(result.getResumeCertificate());
                skillAdapter.replaceAll(certificateBeans, true);
            }
        });
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Constants.type=1;
    }
}
